home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / ICON_8 / CALLING_ / EXTINT.C < prev    next >
Text File  |  1990-04-08  |  2KB  |  57 lines

  1. /*
  2.  * Example of calling C functions by integer codes.  Here it's
  3.  *  one of three UNIX functions:
  4.  *
  5.  *    1: getpid (get process identification)
  6.  *    2: getppid (get parent process identification)
  7.  *    3: getpgrp (get process group)
  8.  */
  9.  
  10. #include "../h/config.h"
  11. #include "../h/rt.h"
  12. #include "rproto.h"
  13.  
  14. struct descrip retval;            /* for returned value */
  15.  
  16. dptr extcall(dargv, argc, ip)
  17. dptr dargv;
  18. int argc;
  19. int *ip;
  20.    {
  21.    int retcode;
  22.    int getpid(), getppid(), getpgrp();
  23.     
  24.    *ip = -1;                /* anticipate error-free execution */
  25.    
  26.    if (cvint(dargv) == CvtFail) {    /* 1st argument must be a string */
  27.       *ip = 101;            /* "integer expected" error number */
  28.       return dargv;            /* return offending value */
  29.       }
  30.  
  31.    switch ((int)IntVal(*dargv)) {
  32.       case 1:                /* getpid */
  33.          retcode = getpid();
  34.          break;
  35.       case 2:                /* getppid */
  36.          retcode = getppid();
  37.          break;
  38.       case 3:                /* getpgrp */
  39.          if (argc < 2) {
  40.             *ip = 205;            /* no error number fits, really */
  41.             return NULL;        /* no offending value */
  42.             }
  43.          dargv++;            /* get to next value */
  44.          if (cvint(dargv) == CvtFail) { /* 2nd argument must be integer */
  45.             *ip = 101;            /* "integer expected" error number */
  46.             return dargv;
  47.             }
  48.          retcode = getpgrp(IntVal(*dargv));
  49.          break;
  50.       default:
  51.          *ip = 216;            /* external function not found */
  52.          return NULL;
  53.       }
  54.    MakeInt(retcode,&retval);        /* make an Icon integer for result */
  55.    return &retval;
  56.    }
  57.